//
//  WXViewController.m
//  WFCoretext
//
//  Created by 阿虎 on 14/10/28.
//  Copyright (c) 2014年 tigerwf. All rights reserved.
//

#import "WXViewController.h"
#import "YMTableViewCell.h"
#import "ContantHead.h"
#import "YMShowImageView.h"
#import "YMTextData.h"
#import "YMReplyInputView.h"
#import "WFReplyBody.h"
#import "WFMessageBody.h"
#import "WFPopView.h"
#import "WFActionSheet.h"
#import "DDShareViewController.h"
#import "DDisBlankString.h"

#import "ShareCustom.h"
//#import "HttpRequestClient.h"
//#import "DDWXViewTopicListRequest.h"
//#import "DDWXViewTopicListResponse.h"
//#import "DDWXViewAnswerListRequest.h"
//#import "DDWXViewAnswerListResponse.h"
//#import "DDWXViewAnswerReplyRequest.h"
//#import "DDWXViewAnswerReplyResponse.h"

#import "AFHTTPSessionManager.h"
#import "DDNetWorkAPIClient.h"
#import "DDQuestionAnswerList.h"

#define dataCount 10
#define kLocationToBottom 20
//#define kAdmin @"小虎-tiger"

@interface WXViewController ()<UITableViewDataSource,UITableViewDelegate,cellDelegate,InputDelegate,UIActionSheetDelegate>
{
    NSMutableArray *_imageDataSource;
    
    NSMutableArray *_contentDataSource;//模拟接口给的数据
    
    NSMutableArray *_tableDataSource;//tableview数据源
    
    NSMutableArray *_shuoshuoDatasSource;//说说数据源
    
    UITableView *mainTable;
    
    UIView *popView;
    
    YMReplyInputView *replyView ;
    
    NSInteger _replyIndex;
    
    //NSMutableArray *responseArr;
    
    NSMutableArray *answerArr;
    
    //DDWXViewTopicListResponse *topicListResponse;//问题列表请求数据
    
    //DDWXViewAnswerListResponse *answerListResponse;//回答列表请求数据
    DDQuestionAnswerList *answerListResponse;//回答列表请求数据
    //DDWXViewAnswerReplyResponse *anwerReplyResponse;//评论列表请求数据
    
    NSMutableDictionary *answerList;//回答列表请求放入字典 key为answerID
    
    //NSString *access_token;//全局token
    NSString *shareBodyText;
    
    WFMessageBody *messBody;
    
    
}
@property (nonatomic,strong) WFPopView *operationView;
@property (nonatomic,strong) NSIndexPath *selectedIndexPath;
@property (nonatomic,retain) UIActivityIndicatorView *activity;
@end

@implementation WXViewController


#pragma mark - 数据源
- (void)configAnswerData{
    
    _tableDataSource = [[NSMutableArray alloc] init];
    _replyIndex = -1;//代表是直接评论
    
    //for(DDWXAnswerList_data_list *item in answerListResponse.data.list)
    int i = 0;
    for(DDQuestionAnswerListCell *item in answerListResponse.list)
    {
        
        //DDWXAnswerList_data_list_explanation *explanation = item.explanation[0];
        //NSLog(@"item.explanation.count=%lu",item.explanation.count);

        WFReplyBody *body = [[WFReplyBody alloc] init];
        body.replyUser = item.nickName;//item.name;
        if (item.parentQname==NULL) {
            body.repliedUser = @"";
        }else{
            body.repliedUser = item.parentQname;
        }
        body.replyUser_head_img = item.userAvatarUrl;
        body.replyTime = item.answerTime;//[item.answerTime stringByReplacingOccurrencesOfString:@" " withString:@"_"];
        body.replyUserID = item.uid;
        if(item.explanation.count>0){
            DDQuestionAnswerExplanation *explanation = item.explanation[0];
            body.replyInfo = explanation.text;
            
        }else if (item.answer != NULL){
            NSLog(@"item.answer不为空");
            body.replyInfo=item.answer;
        }else{
            NSLog(@"item.answer为空");
        }
        i++;
        NSLog(@"第%d条回答：%@",i,body.replyInfo);
        [answerArr addObject:body];
    }
    
    messBody.posterReplies = [NSMutableArray arrayWithArray:answerArr];
    [_contentDataSource replaceObjectAtIndex:0 withObject:messBody];
    //[_contentDataSource addObject:messBody];
}
    
- (void)configQuestionData{
    
    
    messBody = [[WFMessageBody alloc] init];
    
    messBody.tID = self.helpTopicCellModel.id;//发布者发布内容ID = 原晒晒ID
    messBody.qID = ((DDTopicQuestion *)self.helpTopicCellModel.questions[0]).id;
    
    messBody.posterPostImage = [[NSMutableArray alloc] init];
    NSArray *questions = self.helpTopicCellModel.questions;

    NSArray *bodys = questions.count > 0 ?((DDTopicQuestion *)questions[0]).body : nil;
    
    messBody.posterReplies = [NSMutableArray arrayWithArray:answerArr]; //回复内容传赋值初始化
    //发布者回复列表
    //messBody.posterReplies = [NSMutableArray arrayWithArray:repliesArr];
    //发布者的头像
    messBody.posterImgstr = self.helpTopicCellModel.userAvatarUrl;
    //发布者的姓名
    //messBody.posterName = [NSString stringWithFormat:@"%@(u%@t%@q%@)",self.helpTopicCellModel.userName,self.helpTopicCellModel.uid,self.helpTopicCellModel.id,messBody.qID];
    messBody.posterName = self.helpTopicCellModel.userName;
    
    messBody.posterIntro = self.helpTopicCellModel.school;
    messBody.create_time = [self convertTime:self.helpTopicCellModel.createTime];
    messBody.posterFavour = [NSMutableArray arrayWithArray:self.helpTopicCellModel.click_like_man];
    
    messBody.posterContent = ((DDTopicQuestion *)self.helpTopicCellModel.questions[0]).bodyText;
    //用户是否点赞
    if([self.helpTopicCellModel.praiseState isEqualToString:@"1"]){
        messBody.isFavour = YES;
    }else{
        messBody.isFavour = NO;
    }
    shareBodyText=[NSString stringWithFormat:@"%@：%@",self.helpTopicCellModel.userName,messBody.posterContent];

    //bool bodys_is_has_text = NO;
    for(int i = 0; i < bodys.count;i++)
    {

        DDTopicQuestionBody *body = bodys[i];
        if ([body.type isEqualToString:@"IMAGE"])
        {
            //NSLog(@"body.url=%@",((DDWXTopiceList_data_list_question_body *)bodys[i]).url);//body.url);
            //发布者图片列表
            [messBody.posterPostImage addObject:body.url];
            //NSLog(@"messBody.posterPostImage[%d]=%@",i,messBody.posterPostImage);
        }
//        else if ([body.type isEqualToString:@"TEXT"]){
//            //发布者发布内容
//
//            messBody.posterContent = body.text;
//            bodys_is_has_text = YES;
//            if (i<=1) {
//                shareBodyText=[NSString stringWithFormat:@"%@：%@",self.helpTopicCellModel.userName,body.text];
//            }
//            
//        }
//        if (!bodys_is_has_text && i == bodys.count-1){
//            messBody.posterContent = @" ";
//        }
    }
    [_contentDataSource addObject:messBody];
    

}

- (NSString *)convertTime:(NSString *)time
{
    if (!time || [@"" isEqualToString:time]) {
        return @"";
    }
    
    
    NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
    
    long long a =  [timeSp longLongValue] - time.longLongValue/1000;
    
    long long day = a/(3600*24);
    
    if (day < 360 && day > 30) {
        return [NSString stringWithFormat:@"%lld个月前",day/30];
    }
    else if (day >360){
        return [NSString stringWithFormat:@"%lld年以前",day/360];
    }
    else if (day == 0)
    {
        long long second = a/3600;
        if (second > 0 && second < 24) {
            return [NSString stringWithFormat:@"%lld小时前",second];
        }else{
            return [NSString stringWithFormat:@"%lld分钟前",a/60];
        }
        
    }
    else if (day > 1 && day < 6){
        return [NSString stringWithFormat:@"%lld天前",day];
    }else{
        //实例化一个NSDateFormatter对象
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        //设定时间格式,这里可以设置成自己需要的格式
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        //用[NSDate date]可以获取系统当前时间
        NSDate *d = [NSDate dateWithTimeIntervalSince1970:time.longLongValue/1000];
        NSString *dateStr = [dateFormatter stringFromDate:d];
        return dateStr;
    }
    return @"";
}

- (void)viewDidLoad {
    //NSLog(@"self.helpTopicCellModel.id=====%@",self.helpTopicCellModel.id);
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBarHidden = YES;
    //    self.navigationController.navigationBar.hidden = NO;
    [self addNavigatorTitle:NSLocalizedString(@"晒晒详情", nil) parent:self.view];
    self.barViewControl.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top_Background"]];
    
    [self AddLeftBtnAction:nil normal:@"top_返回" selected:@"top_返回" action:^{
        //[self dismissViewControllerAnimated:YES completion:nil];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"reload" object:nil];
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
    [self initTableview];
    
    [self setupCustomData];
    [self configQuestionData];
    [self loadTextData];
    [self get_question_answer_list];
    //[self sendGetAnswerListWithAnswerID];
    self.activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2,200,80,80)];
    self.activity.hidesWhenStopped = YES;
    self.activity.hidden = NO;
    self.activity.color = [UIColor lightGrayColor];
    //启动
    [self.activity startAnimating];
    [self.view addSubview:self.activity];
    NSLog(@"进入到--------->WXViewController");
    
}

#pragma mark
#pragma mark -  一些变量的初始化工作
- (void)setupCustomData
{
    //responseArr = [[NSMutableArray alloc] init];
    answerArr = [[NSMutableArray alloc] init];
    _contentDataSource = [[NSMutableArray alloc] init];
    _tableDataSource = [[NSMutableArray alloc] init];
    answerList = [[NSMutableDictionary alloc] init];
    _replyIndex = -1;//代表是直接评论
    
}


#pragma mark
#pragma mark - 获得AnswerList AFNetWork 请求  //获取回答
//- (void)sendGetAnswerListWithAnswerID
//{
//    //2.准备参数
//    DDSharedUser *userInfo = [DDSharedUser shared];
//    DDWXViewAnswerListRequest *request = [[DDWXViewAnswerListRequest alloc] init];
//    request.access_token = userInfo.access_token;
//    request.topicId = self.helpTopicCellModel.id;
//    request.excludedUid = @"0";
//    request.pageSize = @"300";
//    NSDictionary *paramsDic = [request toDictionary];
//
//
//    //发起请求
//    __weak WXViewController *weakSelf = self;
//    [HttpRequestClient sendWXViewAnswerListRequestWithParams:paramsDic SuccessBlock:^(AFHTTPRequestOperation *opreation, id responseObject) {
//
//        NSError *error = nil;
//        //接到的数据初始化给 answerListResponse
//        answerListResponse  = [[DDWXViewAnswerListResponse alloc] initWithDictionary:responseObject error:&error];
//        [weakSelf configData];
//        [weakSelf loadTextData];
//
//    } FailBlock:^(AFHTTPRequestOperation *opreation, id responseObject) {
//
//    } ErrorBlock:^(AFHTTPRequestOperation *opreation, id responseObject) {
//        NSLog(@"ErrorBlock^responseObject%@", responseObject);
//    }];
//}

- (void)get_question_answer_list{
    
    __weak WXViewController *weakSelf = self;
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    params[@"topicId"] = self.helpTopicCellModel.id;
    params[@"excludedUid"] = @"0";
    params[@"pageSize"] = @"500";
    DDNetWorkAPIClient *network = [[DDNetWorkAPIClient alloc] init];
    [network mainQuestionAnswerList:params completionBlock:^(BOOL isSuccess, NSString *message, NSString *status, id object) {
        [self.activity stopAnimating];
        answerListResponse  = (DDQuestionAnswerList *)object;
        [weakSelf configAnswerData];
        [weakSelf loadTextData];

    }];
    
    
    
    
}


#pragma mark
#pragma mark - 获得topicList AFNetWork 请求
#pragma mark -加载数据

- (void)loadTextData{
    
    NSLog(@"- (void)loadTextData-加载数据");
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSMutableArray * ymDataArray =[[NSMutableArray alloc]init];
        
        for (int i = 0 ; i < _contentDataSource.count; i ++) {
            WFMessageBody *messBody = [_contentDataSource objectAtIndex:i];
            YMTextData *ymData = [[YMTextData alloc] init ];
            ymData.messageBody = messBody;
            [ymDataArray addObject:ymData];
            
        }
        [self calculateHeight:ymDataArray];
        
    });
}



#pragma mark - 计算高度
- (void)calculateHeight:(NSMutableArray *)dataArray{
    
    for (YMTextData *ymData in dataArray) {
        //ymData.shuoshuoHeight = [ymData calculateShuoshuoHeightWithWidth:self.view.frame.size.width withUnFoldState:NO];//折叠
        //ymData.shuoshuoHeight = [ymData calculateShuoshuoHeightWithWidth:self.view.frame.size.width withUnFoldState:YES];//展开
        ymData.unFoldShuoHeight = [ymData calculateShuoshuoHeightWithWidth:self.view.frame.size.width withUnFoldState:YES];//展开
        ymData.replyHeight = [ymData calculateReplyHeightWithWidth:self.view.frame.size.width];
        ymData.favourHeight = [ymData calculateFavourHeightWithWidth:self.view.frame.size.width];
        [_tableDataSource addObject:ymData];
    }
    
    NSDate* tmpStartData = [NSDate date];
    double deltaTime = [[NSDate date] timeIntervalSinceDate:tmpStartData];
  
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [mainTable reloadData];
        
    });
    
    NSLog(@"- (void)calculateHeight:(NSMutableArray *)dataArray - 计算高度");
}




- (void)backToPre{
    
    NSLog(@"- (void)backToPre");
    [self dismissViewControllerAnimated:YES completion:NULL];
}


- (void) initTableview{
    
    NSLog(@"- (void) initTableview");
    mainTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64)];
    mainTable.backgroundColor = [UIColor clearColor];
    // mainTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    mainTable.delegate = self;
    mainTable.dataSource = self;
    [self.view addSubview:mainTable];
    
}

//**
// *  ///////////////////////////////////////////////////
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    NSLog(@"- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section");
    return  _tableDataSource.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath");
    
    YMTextData *ym = [_tableDataSource objectAtIndex:indexPath.row];
    //    BOOL unfold = ym.foldOrNot;
    
    //return TableHeader + kLocationToBottom + ym.replyHeight + ym.showImageHeight  + kDistance + (ym.islessLimit?0:30) + (unfold?ym.shuoshuoHeight:ym.unFoldShuoHeight) + kReplyBtnDistance + ym.favourHeight + (ym.favourHeight == 0?0:kReply_FavourDistance);
    return TableHeader + kLocationToBottom + ym.replyHeight + ym.showImageHeight  + kDistance + (ym.islessLimit?0:30) + ym.unFoldShuoHeight + kReplyBtnDistance + ym.favourHeight + (ym.favourHeight == 0?0:kReply_FavourDistance);
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath");
    static NSString *CellIdentifier = @"ILTableViewCell";
    
    YMTableViewCell *cell = (YMTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[YMTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.stamp = indexPath.row;
    cell.replyBtn.appendIndexPath = indexPath;
//    [cell.share_button addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell.share_button2 addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell.replyBtn addTarget:self action:@selector(replyAction:) forControlEvents:UIControlEventTouchUpInside];
    cell.delegate = self;
    [cell setYMViewWith:[_tableDataSource objectAtIndex:indexPath.row]];
    
    
    
    return cell;
}
- (void)shareAction:(YMButton *)sender{
    /*ShareCustom
     *  @pragma Content 分享主体
     *  @pragma ImageUrlString 头像
     *  @pragma title  标题
     *  @pragma url    链接地址
     *  @pragma sender 发送者
     */
    
    DDSharedUser *userInfo = [DDSharedUser shared];
    NSString *title = [NSString stringWithFormat:@"我是%@%@,我在丁丁当当看到好晒晒，分享一下！",userInfo.userInfo.school,userInfo.userInfo.nickName];
    NSURL *imageUrlString = [[NSBundle mainBundle] URLForResource:@"icon_share.png" withExtension:nil];
    NSString *qid = ((DDTopicQuestion *)self.helpTopicCellModel.questions[0]).id;
    NSString *urlString = [NSString stringWithFormat:@"http://app.dd5s.com:20010/dingdangv2-front/front/share.jhtml?qId=%@",qid];
    
    //WXViewController *weakSelf = self;
    [ShareCustom shareWithContent:shareBodyText
                pngImageUrlString:[imageUrlString absoluteString]
                            title:title
                              url:urlString
                           sender:self.view];
    
    
    
//    DDShareViewController *share = [DDShareViewController alloc];
//    share.accept_qid = ((DDTopicQuestion *)self.helpTopicCellModel.questions[0]).id;
//    NSLog(@"((DDTopicQuestion *)self.helpTopicCellModel.questions[0]).id=%@",((DDTopicQuestion *)self.helpTopicCellModel.questions[0]).id);
//    if (shareBodyText==NULL) {
//        share.accept_qBodyText = @"丁丁当当-大学生互动平台";
//    }else{
//        share.accept_qBodyText = shareBodyText;
//    }
    
//    NSString *qid = ((DDTopicQuestion *)self.helpTopicCellModel.questions[0]).id;
//    DDSharedUser *userInfo = [DDSharedUser shared];
//    NSString *title = [NSString stringWithFormat:@"我是%@%@,我在丁丁当当看到好晒晒，分享一下！",userInfo.userInfo.school,userInfo.userInfo.nickName];
//
//    [DDShareViewController showShareWithController:self withQid:qid title:title qBodyText:shareBodyText];

}
////////////////////////////////////////////////////////////////////

#pragma mark - 按钮动画

- (void)replyAction:(YMButton *)sender{
    NSLog(@"- (void)replyAction:(YMButton *)sender- 按钮动画");
    CGRect rectInTableView = [mainTable rectForRowAtIndexPath:sender.appendIndexPath];
    CGFloat origin_Y = rectInTableView.origin.y + sender.frame.origin.y;
    CGRect targetRect = CGRectMake(CGRectGetMinX(sender.frame), origin_Y, CGRectGetWidth(sender.bounds), CGRectGetHeight(sender.bounds));
    if (self.operationView.shouldShowed) {
        [self.operationView dismiss];
        return;
    }
    _selectedIndexPath = sender.appendIndexPath;
    YMTextData *ym = [_tableDataSource objectAtIndex:_selectedIndexPath.row];
    [self.operationView showAtView:mainTable rect:targetRect isFavour:ym.hasFavour];
}


//评论后1步
- (WFPopView *)operationView {
    NSLog(@"- (WFPopView *)operationView");
    if (!_operationView) {
        _operationView = [WFPopView initailzerWFOperationView];
        WS(ws);
        _operationView.didSelectedOperationCompletion = ^(WFOperationType operationType) {
            switch (operationType) {
                case WFOperationTypeLike:
                    
                    [ws addLike];
                    break;
                case WFOperationTypeReply:
                    [ws replyMessage: nil];
                    break;
                default:
                    break;
            }
        };
    }
    return _operationView;
}

#pragma mark - 赞
- (void)addLike{
    NSLog(@"- (void)addLike - 赞");
    DDSharedUser *userInfo = [DDSharedUser shared];
    YMTextData *ymData = (YMTextData *)[_tableDataSource objectAtIndex:_selectedIndexPath.row];
    WFMessageBody *m = ymData.messageBody;
    DDNetWorkAPIClient *network = [[DDNetWorkAPIClient alloc] init];
    NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
    params[@"topicId"]= self.helpTopicCellModel.id;
    params[@"type"]=@"0";
    
    if (m.isFavour == YES) {//此时该取消赞
        
        [m.posterFavour removeObject:userInfo.userInfo.nickName];
        m.isFavour = NO;
        params[@"praiseType"]=@"1";
    }else{
        [m.posterFavour addObject:userInfo.userInfo.nickName];
        m.isFavour = YES;
        params[@"praiseType"]=@"0";
    }
    NSLog(@"点赞params=%@",params);
    [network click_like_and_cancel:params completionBlock:^(BOOL isSuccess, NSString *message, NSString *status, id object) {
        
        if(isSuccess){
            NSLog(@"点击成功");
        }else{
            NSLog(@"点击失败");
        }
    }];
    
    ymData.messageBody = m;
    
    
    //清空属性数组。否则会重复添加
    
    [ymData.attributedDataFavour removeAllObjects];
    
    
    ymData.favourHeight = [ymData calculateFavourHeightWithWidth:self.view.frame.size.width];
    [_tableDataSource replaceObjectAtIndex:_selectedIndexPath.row withObject:ymData];
    
    [mainTable reloadData];
    
}


#pragma mark - 真の评论
- (void)replyMessage:(YMButton *)sender{
    NSLog(@"- (void)replyMessage:(YMButton *)sender - 真の评论");
    if (replyView) {
        return;
    }
    replyView = [[YMReplyInputView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 44, screenWidth,44) andAboveView:self.view];
    replyView.delegate = self;
    replyView.replyTag = _selectedIndexPath.row;
    replyView.help_TopicCellModel = self.helpTopicCellModel;
    [self.view addSubview:replyView];
    
}


#pragma mark -移除评论按钮
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"- (void)replyMessage:(YMButton *)sender-移除评论按钮");
    [self.operationView dismiss];
    
}


#pragma mark -cellDelegate
- (void)changeFoldState:(YMTextData *)ymD onCellRow:(NSInteger)cellStamp{
    NSLog(@"- (void)changeFoldState:(YMTextData *)ymD onCellRow:(NSInteger)cellStamp-移除评论按钮");
    [_tableDataSource replaceObjectAtIndex:cellStamp withObject:ymD];
    [mainTable reloadData];
    
}

#pragma mark - 图片点击事件回调
- (void)showImageViewWithImageViews:(NSArray *)imageViews byClickWhich:(NSInteger)clickTag{
    NSLog(@"- (void)changeFoldState:(YMTextData *)ymD onCellRow:(NSInteger)cellStamp - 图片点击事件回调");
    UIView *maskview = [[UIView alloc] initWithFrame:self.view.bounds];
    maskview.backgroundColor = [UIColor blackColor];
    [self.view addSubview:maskview];
    
    
    
    YMShowImageView *ymImageV = [[YMShowImageView alloc] initWithFrame:self.view.bounds byClick:clickTag appendArray:imageViews];
    [ymImageV show:maskview didFinish:^(){
        
        [UIView animateWithDuration:0.5f animations:^{
            
            ymImageV.alpha = 0.0f;
            maskview.alpha = 0.0f;
            
        } completion:^(BOOL finished) {
            
            [ymImageV removeFromSuperview];
            [maskview removeFromSuperview];
        }];
        
    }];
    
}

#pragma mark - 长按评论整块区域的回调
- (void)longClickRichText:(NSInteger)index replyIndex:(NSInteger)replyIndex{
    NSLog(@"- (void)longClickRichText:(NSInteger)index replyIndex:(NSInteger)replyIndex - 长按评论整块区域的回调");
    [self.operationView dismiss];
    YMTextData *ymData = (YMTextData *)[_tableDataSource objectAtIndex:index];
    WFReplyBody *b = [ymData.messageBody.posterReplies objectAtIndex:replyIndex];
    
    UIPasteboard *pboard = [UIPasteboard generalPasteboard];
    pboard.string = b.replyInfo;
    
}

#pragma mark - 点评论整块区域的回调
- (void)clickRichText:(NSInteger)index replyIndex:(NSInteger)replyIndex{
    NSLog(@"- (void)clickRichText:(NSInteger)index replyIndex:(NSInteger)replyIndex - 点评论整块区域的回调");
    
    DDSharedUser *userInfo = [DDSharedUser shared];
    [self.operationView dismiss];
    
    _replyIndex = replyIndex;
    
    YMTextData *ymData = (YMTextData *)[_tableDataSource objectAtIndex:index];
    WFReplyBody *b = [ymData.messageBody.posterReplies objectAtIndex:replyIndex];
    if ([b.replyUser isEqualToString:userInfo.userInfo.nickName]) {
        WFActionSheet *actionSheet = [[WFActionSheet alloc] initWithTitle:@"删除评论？" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil, nil];
        actionSheet.actionIndex = index;
        [actionSheet showInView:self.view];
    
    }else{
        //回复
        
        if (replyView) {
            return;
        }
        replyView = [[YMReplyInputView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 44, screenWidth,44) andAboveView:self.view];
        replyView.delegate = self;
        replyView.lblPlaceholder.text = [NSString stringWithFormat:@"回复%@:",b.replyUser];
        replyView.replyTag = index;
        replyView.help_TopicCellModel = self.helpTopicCellModel;
        NSLog(@"b.replyUserID=%@",b.replyUserID);
        replyView.parent_Uid = [b.replyUserID copy];//传回复人ID
        NSLog(@"replyView.parent_Uid=%@",replyView.parent_Uid);
        [self.view addSubview:replyView];
    }
}

#pragma mark - 评论说说回调
- (void)YMReplyInputWithReply:(NSString *)replyText appendTag:(NSInteger)inputTag{
    NSLog(@"- (void)YMReplyInputWithReply:(NSString *)replyText appendTag:(NSInteger)inputTag - 评论说说回调");
    DDSharedUser *userInfo = [DDSharedUser shared];
    YMTextData *ymData = nil;
    if (_replyIndex == -1) {
        
        WFReplyBody *body = [[WFReplyBody alloc] init];
        body.replyUser = userInfo.userInfo.nickName;
        body.repliedUser = @"";
        body.replyInfo = replyText;
        body.replyUser_head_img = userInfo.userInfo.avatarUrl;
        
        NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
        body.replyTime = [formatter stringFromDate:[NSDate date]];
        
        ymData = (YMTextData *)[_tableDataSource objectAtIndex:inputTag];
        WFMessageBody *m = ymData.messageBody;
        //        [m.posterReplies addObject:body];
        //将评论置顶
        [m.posterReplies insertObject:body atIndex:0];
        ymData.messageBody = m;
        
    }else{
        
        ymData = (YMTextData *)[_tableDataSource objectAtIndex:inputTag];
        WFMessageBody *m = ymData.messageBody;
        
        WFReplyBody *body = [[WFReplyBody alloc] init];
        body.replyUser = userInfo.userInfo.nickName;
        body.repliedUser = [(WFReplyBody *)[m.posterReplies objectAtIndex:_replyIndex] replyUser];
        body.replyInfo = replyText;
        body.replyUser_head_img = userInfo.userInfo.avatarUrl;
        
        NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
        body.replyTime = [formatter stringFromDate:[NSDate date]];
        
        //        [m.posterReplies addObject:body];
        //将评论置顶
        [m.posterReplies insertObject:body atIndex:0];
        ymData.messageBody = m;

    }
    
    
    
    //清空属性数组。否则会重复添加
    //[ymData.replyHeadImgArray removeAllObjects];
    //[ymData.replyTimeArray removeAllObjects];
    [ymData.completionReplySource removeAllObjects];
    [ymData.attributedDataReply removeAllObjects];
    
    
    ymData.replyHeight = [ymData calculateReplyHeightWithWidth:self.view.frame.size.width];
    [_tableDataSource replaceObjectAtIndex:inputTag withObject:ymData];
    
    [mainTable reloadData];
    
}

- (void)destorySelf{
    NSLog(@"- (void)destorySelf");
    //  NSLog(@"dealloc reply");
    [replyView removeFromSuperview];
    replyView = nil;
    _replyIndex = -1;
    
}

- (void)actionSheet:(WFActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"- (void)actionSheet:(WFActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex");
    if (buttonIndex == 0) {
        //delete
        YMTextData *ymData = (YMTextData *)[_tableDataSource objectAtIndex:actionSheet.actionIndex];
        WFMessageBody *m = ymData.messageBody;
        [m.posterReplies removeObjectAtIndex:_replyIndex];
        ymData.messageBody = m;
        [ymData.replyTimeArray removeAllObjects];
        [ymData.completionReplySource removeAllObjects];
        [ymData.attributedDataReply removeAllObjects];
        
        
        ymData.replyHeight = [ymData calculateReplyHeightWithWidth:self.view.frame.size.width];
        [_tableDataSource replaceObjectAtIndex:actionSheet.actionIndex withObject:ymData];
        
        [mainTable reloadData];
        
    }else{
        
    }
    _replyIndex = -1;
}

- (void)dealloc{
    
    NSLog(@"销毁");
    
}

@end
